﻿using HZY.Framework.DependencyInjection;
using Long.DAL;
using Long.Helper;
using Long.Model;
using Mapster;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Long.BLL
{
    public class DataManager : IScopedSelfDependency
    {
        public readonly DataService _dataService;
        public DataManager(DataService dataService)
        {
            _dataService = dataService;
        }

        public async Task<BaseResult> AddDataAsyncManager(DataAddDto request)
        {
            DataEntity entity = request.Adapt<DataEntity>();
            int res = await _dataService.InsertAsync(entity);

            if (res < 1)
            {
                return new BaseResult() { ResultStatus = SystemEnums.ResultStatus.Fail, Msg = "新增失败" };
            }
            return new BaseResult() { ResultStatus = SystemEnums.ResultStatus.Success };
        }

        public async Task<BaseResult<DataQuaeryResulyDto>> GetDataListByTimeAsyncManager(DataQueryDto request)
        {
            //List<DataEntity> entity = await _dataService.GetByListAsync(e=>request.StartTime<= e.InsertTime && e.InsertTime <= request.EndTime);
            List<DataEntity> entity = await _dataService.GetByListAsync(e => SqlFunc.Between(e.InsertTime,request.StartTime,request.EndTime));
           // List<DataQuaeryResulyDto>? res = entity.Adapt<List<DataQuaeryResulyDto>>();

            return new BaseResult<DataQuaeryResulyDto>() { ResultStatus = SystemEnums.ResultStatus.Success, Data = entity.Adapt<List<DataQuaeryResulyDto>>() };
        }
    }
}
